package com.kaochong.xcx.utils;

import java.math.BigDecimal;

/**
 * @author han
 * @date 2018-05-06 17:12
 */
public class CalculateUtil {
	
	/**
	 * 百分比计算
	 * @param percent 百分比
	 * @param sum 总数
	 * @return 数量
	 */
	public static Integer calcPercent(Integer percent, Integer sum){
		if (sum == 0) {
			return 0;
		}
		BigDecimal res = new BigDecimal(percent).multiply(new BigDecimal(sum)).divide(new BigDecimal("100")).setScale(0,BigDecimal.ROUND_UP);
		Integer result = res.intValue();
		return result;
	}
	
	/**
	 * 除法，向下取整，保留整数
	 * @param a
	 * @param b
	 * @return
	 */
	public static Integer divideRoundDown(Integer a, Integer b){
		BigDecimal schedule = new BigDecimal(a).divide(new BigDecimal(b)).multiply(new BigDecimal("100")).setScale(0,BigDecimal.ROUND_DOWN);
		return schedule.intValue();
	}
	
	public static void main(String[] args) {
		
		
		System.out.println(test(12));
	}
	
	
	public static Integer test(Integer currStage){
		Integer percent = 0;
		
		switch (currStage) {
			case 11:
				percent = 20;
			case 12:
				percent = 40;
				Integer num = CalculateUtil.calcPercent(percent, 50);
				break;
			case 13:
				break;
			default:
				break;
		}
		return percent;
	}
}
